package com.mimosa.common.system.log;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

import com.mimosa.util.constant.StringConstUtil;

/**
 * 读取 Log_Resource.properties
 * 
 * @author yunjum
 * @date 2012-11-13 14:22
 */
public class LogProperty {

	private static final String PROPERTIES = "/Log_Resource.properties";
	/**
	 * 单一实例
	 */
	private static final LogProperty INS = new LogProperty();
	/**
	 * 属性对象
	 */
	private Properties properties = new Properties();

	/**
	 * 私有构造函数
	 *
	 */
	private LogProperty() {
		this.loadProperties();
	}

	/**
	 * 读取属性
	 * 
	 * @param s
	 * @return
	 */
	public static String getText(String s) {
		if (StringUtils.isBlank(s)) {
			return StringConstUtil.EMPTY;
		}
		return INS.properties.getProperty(s.trim());
	}

	/**
	 * 读取属性
	 * 
	 * @param s
	 * @return
	 */
	public static String getText(String s, Object... objects) {
		if (StringUtils.isBlank(s)) {
			return StringConstUtil.EMPTY;
		}
		return MessageFormat.format(INS.properties.getProperty(s.trim()),
				objects);
	}

	/**
	 * loadProperties:(加截日志的描述信息). <br/>
	 *
	 * @author Administrator
	 * @since JDK 1.7
	 */
	private void loadProperties() {
		try {
			properties.load(LogProperty.class.getResourceAsStream(PROPERTIES));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
